# def func():
#     print(111)
#     return 2
# ret = func()
# print(ret)
# 执行此函数，遇到return结束函数。
# 将数字2返回给ret。



def func():
    # print(111)
    # print(111)
    # print(111)
    # print(111)
    # print(111)
    # print(111)
    yield 2,4,5
    yield 3
    yield 4
    yield 5
ret = func()  # 生成器对象
# print(ret)  # <generator object func at 0x0000000001E10F68>
'''
# 类比
l1 = [2,]  [2,3,4,5]
obj = iter(l1)

'''
# 只要函数中出现了yield那么他就不是函数，它是生成器函数。
# 一个next对应一个yield.
# print(next(ret))
# print(next(ret))
# print(next(ret))
# print(next(ret))
# print(next(ret))
# print(next(ret))

# return yield
# return 结束函数，给函数的执行者返回值(多个值通过元组的形式返回)。
# yield  不结束函数，对应着给next返回值(多个值通过元组的形式返回)。


# 举例说明：

# def eat_baozi():
#     list1 = []
#     for i in range(1,2001):
#         list1.append(f'{i}号包子')
#     return list1
#
# print(eat_baozi())

def eat_baozi_gen():
    for i in range(1,2001):
        # print(11)
        yield f'{i}号包子'

'''
# ret1 = eat_baozi_gen()
# ret2 = eat_baozi_gen()
# # print(ret1)
# # print(ret2)
# print(next(ret1))
# print(next(ret1))
# print(next(ret1))
# 
# print(next(ret2))
# print(next(ret2))
# print(next(ret2))
# print(next(ret))
# print(next(ret))
'''

# ret = eat_baozi_gen()
#
# for i in range(200):
#     print(next(ret))
#
# for i in range(200):
#     print(next(ret))


# yield from


# def func():
#     l1 = [1, 2, 3]
#     yield l1
# ret = func()
# print(next(ret))
# print(next(ret))
# print(next(ret))



# def func():
#     l1 = [1, 2, 3]
#     yield from l1
#
#     '''
#     yield 1
#     yield 2
#     yield 3
#     '''
# ret = func()
# print(next(ret))
# print(next(ret))
# print(next(ret))

# yield : 对应next给next返回值
# yield from 将一个可迭代对象的每一个元素返回给next
# yield from 节省代码，提升效率（代替了for循环）
